home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 224_01 / hoc.hlp < prev    next >
Text File  |  1987-01-02  |  5KB  |  123 lines

  1. NAME
  2.     hoc - an interactive language for floating point arithmetic
  3.     
  4. SYNTAX
  5.     hoc [file_list]
  6.  
  7. DESCRIPTION
  8.     Hoc is a simple interpreter for floating point arithmetic.  It has 
  9.     C-style control flow, function definitions, expressions, and the standard
  10.     built-in functions like sin() and log().  Hoc will read and execute the 
  11.     statements in the specified files, where the '-' can be used to imply the
  12.     standard input.  If no files are specified, hoc will take its input from
  13.     the standard input.  The output from the "print" statement and any results
  14.     from expressions are printed on the standard output.
  15.     
  16.     Hoc, being a simple interpreter, is slow for complicated calculations; but
  17.     provides an excellent interface for doing quick calculations.  It is also
  18.     easy to use since it does not require reverse-Polish notation and accepts 
  19.     C-style expressions.
  20.         
  21.     All expressions are considered floating point expressions.  Valid 
  22.     expressions "expr" include a number, variable, ( expr ), expr binop expr,
  23.     unop expr, or function ( arguments ).
  24.     
  25.     Variables can be created in an assignment statement by:
  26.     
  27.     variable_name = expression
  28.     
  29.     Note that statements are terminated by the carriage return (unlike C where
  30.     the statements are terminated by the semicolon).  A variable name is a 
  31.     letter followed by a string of letters and numbers. 
  32.  
  33.     The following binary operators, "binop", and the unary operators,,"unop", 
  34.     are in order of precedence:
  35.     
  36.     ^        exponentiation
  37.     !   -        unary negation: logical and arithmetic
  38.     *   /        multiplication and division
  39.     +   -          addition and subtraction
  40.     >   >=    <   <=    relational operators: greater than, greater or equal,
  41.         ==  !=        less than, less than or equal, equal, not equal
  42.     &&        logical AND
  43.     ||        logical OR
  44.     =        assignment
  45.     
  46.     Functions can be defined by the user in the following format:
  47.     
  48.     func function_name() statement_list
  49.     
  50.     The arguments can be accessed inside a function by $1, $2, ... .  The 
  51.     following is an example function.  Note that semicolons are not used
  52.     to terminate a statement as in a C program.
  53.     
  54.     func max() {
  55.         if ($1 > $2) return $2 else return $1
  56.         }
  57.     
  58.     The built-in functions are (with all angles specified in degrees):
  59.     
  60.     abs(x)        absolute value of x
  61.     int(x)        integer part of x, truncated towards zero
  62.     sqrt(x)        square root of x
  63.     cos(x)        Cosine of x
  64.     sin(x)        sine of x
  65.     tan(x)        tangent of x
  66.     acos(x)        arc cosine of x
  67.     asin(x)        arc sine of x
  68.     atan(x)        arc tangent of x
  69.     exp(x)        exponential base e of x:   E ^ x
  70.     exp10(x)    exponential base 10 of x: 10 ^ x
  71.     log(x)        logarithm base e of x
  72.     log10(x)    logarithm base 10 of x
  73.     
  74.     The built-in constants are:
  75.     
  76.     DEG    57.29577951308232087680        180 / PI, degrees per radian
  77.     E     2.71828182845904523536        base e of natural logarithm
  78.     GAMMA      0.57721566490153286060        Euler-Mascheroni constant
  79.     PHI     1.61803398874989484820        the golden ratio, (sqrt(5)+1)/2
  80.     PI     3.14159265358979323846        180 degrees in radians
  81.     
  82.     The valid statements for hoc are expr, variable = expr, print expr_list,
  83.     procedure (arguments), return, return expr, while (expr) statement, 
  84.     if (expr) statement, if (expr) statement else statement, or 
  85.     { statement_list }.   Because newlines are mandatory for statements, use
  86.     brackets, { and }, to put statements on separate lines; for example:
  87.     
  88.     if (x < 0)
  89.         print -x,"\n"
  90.     else
  91.         print x,"\n"
  92.     
  93.     is an invalid statement, but :
  94.     
  95.     if (x < 0) {
  96.         print -x,"\n"
  97.     } else {
  98.         print x,"\n"
  99.     }
  100.     
  101.     is a valid statement!
  102.     
  103.     The only input and output interface are the "read" function and the 
  104.     "print" statement.  The input function, read(x), will read the standard 
  105.     input, which must be a number, and store in the variable x.  The return 
  106.     value of read() is 1 if a value was read, else 0 if an error occurred or 
  107.     end of file found. The "print" statement can have a list of expressions and
  108.     strings following "print" separated by commas.  Print will not add a 
  109.     newline at the end, so it must be done explicitly with a string with the 
  110.     last character being '\n'.  Examples:
  111.     
  112.     if (read(x)) print "x = ", x, "\n"
  113.     
  114.     print "This is an example only", sin(45 / DEG), PI * E / 4.5E20
  115.  
  116. REFERENCE
  117.     Hoc is a modified version of the hoc listed in appendix 3 of :
  118.     
  119.     Kernighan, B.W. and Pike, R., 1984. "The UNIX Programming Environment".
  120.     Englewood Cliffs: Prentice-Hall, Inc..
  121.     
  122.     The version of hoc in UTILIX is a freeware software.
  123.